<?php
namespace EasyVote\EasyVoteBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
use EasyVote\EasyVoteBundle\Entity\Department;
use EasyVote\EasyVoteBundle\Entity\Degree;

/**
 * Class LoadDegreeData
 * Loads degree data into the database
 * @package EasyVote\EasyVoteBundle\DataFixtures\ORM
 */
class LoadDegreeData extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * {@inheritDoc}
     */
    public function load(ObjectManager $manager)
    {
        //Get department objects
        $departmentRepository = $manager->getRepository('EasyVoteBundle:Department');
        $degreeTypeRepository = $manager->getRepository('EasyVoteBundle:DegreeType');

        $ba = $degreeTypeRepository->findOneByName('BA');
        $bs = $degreeTypeRepository->findOneByName('BS');
        $ma = $degreeTypeRepository->findOneByName('MA');
        $ms = $degreeTypeRepository->findOneByName('MS');
        $phd = $degreeTypeRepository->findOneByName('PhD');

        //Computer Science and Engineering
        $cse = $departmentRepository->findOneByName('Department of Computer Science and Engineering');

        //Computer Science, BS
        $bs_cs = new Degree();
        $bs_cs->setType($bs);
        $bs_cs->setField("Computer Science");
        $bs_cs->setDepartment($cse);
        $manager->persist($bs_cs);
        $manager->flush();

        //Computer Engineering, BS
        $bs_ce = new Degree();
        $bs_ce->setType($bs);
        $bs_ce->setField("Computer Engineering");
        $bs_ce->setDepartment($cse);
        //$bs_ce->setDescription("Bachelor of Science in Computer Engineering");
        $manager->persist($bs_ce);
        $manager->flush();

        //Information Technology, BA
        $ba_it = new Degree();
        $ba_it->setType($ba);
        $ba_it->setField("Information Technology");
        $ba_it->setDepartment($cse);
        //$ba_it->setDescription("Bachelor of Arts in Information Technology");
        $manager->persist($ba_it);
        $manager->flush();

        //Computer Science, MS
        $ms_cs = new Degree();
        $ms_cs->setType($ms);
        $ms_cs->setField("Computer Science");
        $ms_cs->setDepartment($cse);
        //$ms_cs->setDescription("Master of Science in Computer Science");
        $manager->persist($ms_cs);
        $manager->flush();

        //Computer Engineering, MS
        $ms_ce = new Degree();
        $ms_ce->setType($ms);
        $ms_ce->setField("Computer Engineering");
        $ms_ce->setDepartment($cse);
        //$ms_ce->setDescription("Master of Science in Computer Engineering");
        $manager->persist($ms_ce);
        $manager->flush();

        //Computer Science and Engineering, PhD
        $phd_cse = new Degree();
        $phd_cse->setType($phd);
        $phd_cse->setField("Computer Science and Engineering");
        $phd_cse->setDepartment($cse);
        //$phd_cse->setDescription("PhD in Computer Science and Engineering");
        $manager->persist($phd_cse);
        $manager->flush();

    }

    /**
     * {@inheritDoc}
     */
    public function getOrder()
    {
        return 7; // the order in which fixtures will be loaded
    }
}

?>
